/*
 * @lc app=leetcode.cn id=819 lang=javascript
 *
 * [819] 最常见的单词
 */

// @lc code=start
/**
 * @param {string} paragraph
 * @param {string[]} banned
 * @return {string}
 */
var mostCommonWord = function (paragraph, banned) {
  let max = 0;
  let result = '';
  let map = {};
  paragraph
    .replace(/[^a-zA-Z]+/g, ' ')
    .split(' ')
    .forEach(item => {
      item = item.toLowerCase();
      if (banned.includes(item)) return
      map[item] = map[item] ? map[item] + 1 : 1
      if (map[item] > max) {
        max = map[item];
        result = item;
      }
    });
  return result;
};
// @lc code=end

